﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Tilver.Coder.Utility;

namespace Tilver.Coder.Core
{
    /// <summary>
    /// 索引
    /// </summary>
    [Serializable]
    public class CoderIndex : CoderObjectBase
    {
        /// <summary>
        /// 所属表
        /// </summary>
        [XmlIgnore]
        public CoderTable Table { get; set; }
        ///// <summary>
        ///// 所属表名
        ///// </summary>
        //public string TableName { get; set; }
        /// <summary>
        /// 是否主健
        /// </summary>
        public bool IsPrimaryKey { get; set; }
        /// <summary>
        /// 是否是唯一索引
        /// </summary>
        public bool IsUnique { get; set; }
        /// <summary>
        /// 是否是聚集索引
        /// </summary>
        public bool IsClustered { get; set; }
        /// <summary>
        /// 关联列名
        /// </summary>
        public List<string> MemberColumnNames { get; set; }

        private IEnumerable<CoderColumn> _memberColumns = null;
        /// <summary>
        /// 关联列
        /// </summary>
        public IEnumerable<CoderColumn> MemberColumns
        {
            get { return _memberColumns ?? (_memberColumns = this.Table.FindColumns(MemberColumnNames)); }
        }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
    }
}
